<template>
	<view class="community">
		<view class="head_bg" style="height: 60rpx;"></view>
		<view class="big_box" style="top: -60rpx;">
			<view class="count_tab">
				<view :class="{count_tab_inner: istrue == true,is_active: tabIndex == 1}" @tap="tabSelect" :data-id="1" style="margin-left: 145rpx;">日结算</view>
				<view :class="{count_tab_inner: istrue == true,is_active: tabIndex == 2}" @tap="tabSelect" :data-id="2" style="margin-right: 145rpx;">月结算</view>
			</view>
			<view  v-if="tabIndex == 1">
				<view class="operating_box" style="margin-top: 45rpx;padding-bottom: 0;">
					<view class="equ_list" v-for="(infor,index) in list" :key="index">
						<view class="equ_list_title">
							<view class="equ_list_title_left">{{infor.settlement_time}}</view>
							<view class="equ_status" style="color: red;">结算:{{infor.settlement_amount}}元</view>
						</view>
						<view class="equ_list_comm" style="border-bottom: none;">
							<view class="equ_list_inner1" style="padding-top: 0;margin-left: 0;">
								<view class="equ_list_inner_text1" style="width: 50%;">收入:{{infor.order_income}}元</view>
								<view class="equ_list_inner_text1" style="width: 50%;text-align: right;">套餐:{{infor.set_meal_income}}元</view>
							</view>
							<view class="operating_box_inner">
								<view class="money_details_inner money_details_inner1" style="margin-top: 20rpx;">
									<view class="money_details_number" style="color: #333333;">{{infor.order_num}}次</view>
									<view class="money_details_text" style="color: #666666;">充电次数</view>
								</view>
								<view class="detail_br" style="border-left: 1rpx solid #EDEDED;position: relative;top: 25rpx;"></view>
								<view class="money_details_inner money_details_inner1" style="margin-top: 20rpx;">
									<view class="money_details_number" style="color: #333333;">{{infor.pv_amount}}元</view>
									<view class="money_details_text" style="color: #666666;">单次均价</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view style="height:100rpx;"></view>
				<view v-if="list.length==0" class="margin-top-lg text-center">
					<image src='../../common/img/no_data.png' style="width:275rpx;height:312rpx;"></image>
				</view>
				<view v-if="list.length>0" class="text-black text-df text-center bg-white padding-sm padding-left-lg be-gray">
					{{loadingTxt}} 共({{list.length}}条记录)
				</view>
			</view>
			<view v-if="tabIndex == 2">
				<view class="operating_box" style="margin-top: 45rpx;padding-bottom: 0;">
					<view class="equ_list" v-for="(infom,index) in list" :key="index">
						<view class="equ_list_title">
							<view class="equ_list_title_left">{{infom.settlement_month}}</view>
							<view class="equ_status" style="color: red;">结算:{{infom.settlement_amount}}元</view>
						</view>
						<view class="equ_list_comm" style="border-bottom: none;">
							<view class="equ_list_inner1" style="padding-top: 0;margin-left: 0;">
								<view class="equ_list_inner_text1" style="width: 50%;">收入:{{infom.order_income}}元</view>
								<view class="equ_list_inner_text1" style="width: 50%;text-align: right;">套餐:{{infom.set_meal_income}}元</view>
							</view>
							<view class="operating_box_inner">
								<view class="money_details_inner money_details_inner1" style="margin-top: 20rpx;">
									<view class="money_details_number" style="color: #333333;">{{infom.order_num}}次</view>
									<view class="money_details_text" style="color: #666666;">充电次数</view>
								</view>
								<view class="detail_br" style="border-left: 1rpx solid #EDEDED;position: relative;top: 25rpx;"></view>
								<view class="money_details_inner money_details_inner1" style="margin-top: 20rpx;">
									<view class="money_details_number" style="color: #333333;">{{infom.pv_amount}}元</view>
									<view class="money_details_text" style="color: #666666;">单次均价</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view style="height:100rpx;"></view>
				<view v-if="list.length==0" class="margin-top-lg text-center">
					<image src='../../common/img/no_data.png' style="width:275rpx;height:312rpx;"></image>
				</view>
				<view v-if="list.length>0" class="text-black text-df text-center bg-white padding-sm padding-left-lg be-gray">
					{{loadingTxt}} 共({{list.length}}条记录)
				</view>
			</view>
			</view>
		</view>
	</view>
</template>

<script>
	let page=1,timer=null
	export default {
		data() {
			return {
				loadingTxt:'加载更多',
				tabIndex: 1,
				istrue:true,
				list:[],//全部订单
			}
		},
		onShow() {
			page=1;
			this.getalllist();
		},
		methods: {
			tabSelect(e) {
				page=1;
				this.tabIndex = e.currentTarget.dataset.id;
				this.list=[];
				this.loadingTxt='加载更多',
				this.getalllist();
			},
			getalllist(){
				let that=this;
				let url;
				if(this.tabIndex==1){
					url="settlement/v1/day";
				}else if(this.tabIndex==2){
					url="settlement/v1/month";
				}
				that.http.tokenreq({
					url:url,
					data:{'pageindex':page}
				}).then((res) => {
					let e=res.data;
					console.log("e="+JSON.stringify(e));
					if(e.code==0 && e.success){
						that.list=e.rows;
						page++
					}
				})
			},
			getmorelist(){
				this.loadingTxt='加载中'
				let that=this;
				let url;
				if(this.tabIndex==1){
					url="settlement/v1/day";
				}else if(this.tabIndex==2){
					url="settlement/v1/month";
				}
				that.http.tokenreq({
					url:url,
					data:{'pageindex':page}
				}).then((res) => {
					uni.hideLoading();
					let e=res.data;
					if(e.code==0 && e.success){
						if(e.rows.length==0){
							that.loadingTxt="已经加载全部";
							return;
						}
						that.list=that.list.concat(e.rows);
						page++;
					}
				})
			},
			onReachBottom() {
				//阻止重复加载
				if(timer !== null){
					clearTimeout(timer)
				}
				timer=setTimeout(()=>this.getmorelist(),500)
			},
		}
	}
</script>
